package com.taotao.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.taotao.common.pojo.EasyUITree;
import com.taotao.mapper.TbItemCatMapper;
import com.taotao.pojo.TbItemCat;
import com.taotao.pojo.TbItemCatExample;
import com.taotao.pojo.TbItemCatExample.Criteria;
import com.taotao.service.ItemCatService;


@Service
public class ItemCatServiceImpl implements ItemCatService{
	
	@Autowired
	private TbItemCatMapper itemCatMapper;

	@Override
	public List<EasyUITree> getCatList(long perentId) {
		TbItemCatExample example=new TbItemCatExample();
		
		Criteria criteria=example.createCriteria();
		criteria.andParentIdEqualTo(perentId);
		List<TbItemCat> list=itemCatMapper.selectByExample(example);
		
		List<EasyUITree> resList=new ArrayList<>();
		for (TbItemCat tbItemCat : list) {
			EasyUITree node=new EasyUITree();
			node.setId(tbItemCat.getId());
			node.setText(tbItemCat.getName());
			node.setState(tbItemCat.getIsParent()?"closed":"open");
			resList.add(node);
		}
		
		return resList;
	}

}
